#include<stdio.h>
int main ()
{
	int k,t;int x,y;
	int result;
	scanf("%d",&t);
	for(k=1;k<=t;k++)
	{
		scanf("%d",&x);
		result=(x*x)%10000;
		printf("%d\n",result);
	}
}
